package com.example.zbh.dsliao.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easemob.chat.EMContact;
import com.example.zbh.dsliao.R;
import com.example.zbh.dsliao.ui.activty.GroupBlackListActivity;

import java.util.List;

/**
 * 黑名单列表适配器
 */
public class BlackListAdapter  extends RecyclerView.Adapter<BlackListAdapter.BlackViewHolder>{
    private List<String> List;
    private EMContact contact;

    public void addData(List<String> datas){
        this.List = datas;
        notifyDataSetChanged();
    }


    @Override
    public BlackViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View v = inflater.inflate(R.layout.activity_black_gut, null);
        return new BlackViewHolder(v);
    }

    @Override
    public void onBindViewHolder(BlackViewHolder holder, final int position) {
        if (List != null && List.size() > 0){
            final String blackUsername = List.get(position);
            holder.blackUserTv.setText(blackUsername);//设置名字

            holder.blackUserlayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onBlackClickListener != null){
                        onBlackClickListener.onBlackClickListener(v, blackUsername);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return List != null && List.size() > 0 ? List.size() : 0;
    }



    class BlackViewHolder extends RecyclerView.ViewHolder{

        private TextView blackUserTv;
        private ImageView blackUserImg;
        private LinearLayout blackUserlayout;

        public BlackViewHolder(View itemView) {
            super(itemView);
            blackUserImg = (ImageView) itemView.findViewById(R.id.blackUserImg);
            blackUserTv = (TextView) itemView.findViewById(R.id.blackUserTv);
            blackUserlayout = (LinearLayout) itemView.findViewById(R.id.blackUserlayout);
        }
    }

    //自定义接口传回当前点击的username
    private OnBlackClickListener onBlackClickListener;
    public void setOnBlackClickListener(OnBlackClickListener onBlackClickListener){
        this.onBlackClickListener = onBlackClickListener;
    }
    public interface OnBlackClickListener {
        void onBlackClickListener(View v, String username);
    }


}
